//1.
#include <stdio.h>
#include <string.h>

//反转字符串
void reverseWord(char *start,char *end)
{
    while(start < end)
    {
        char temp = *start;
        *start = *end;
        *end = temp;
        start++;
        end--;
    }
}

//根据空格进行反转
void reverseSentence(char *string)
{
    char *start = string;
    char *temp = string;

    reverseWord(start,start+strlen(string)-1);

    while(*temp)
    {
        if(*temp == ' ')
        {
            reverseWord(start,temp-1);
            start = temp + 1;
        }
        temp++;
    }
    reverseWord(start,temp-1);

}

int main(int argc, char const *argv[])
{
    char buffer[20];
    printf("请输入字符串：\n");
    fgets(buffer,20,stdin);
    buffer[strcspn(buffer,"\n")] = '\0';

    reverseSentence(buffer);

    printf("%s\n",buffer);

    return 0;
}
